package com.xuchao.rabbit.b8;

import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DeliverCallback;
import com.xuchao.rabbit.utils.RabbitMqUtils;

/**
 * @Author xuchao
 * @Date:2023/6/8 13:06
 * @description 死信消费者
 * @Version 1.0
 */
public class DeadConcumer {
    //普通交换机的名称
    public static final String DEAD_EXCHANGE = "dead_exchange";
    public static final String DEAD_QUEUE = "dead_queue";

    public static void main(String[] args) throws Exception {
        Channel channel = RabbitMqUtils.getChannel();
        channel.exchangeDeclare(DEAD_EXCHANGE, BuiltinExchangeType.DIRECT);
        DeliverCallback deliverCallback = (consumerTag,message)->{
            System.out.println("死信队列接收消息："+new String(message.getBody(),"UTF-8"));
        };
        channel.basicConsume(DEAD_QUEUE,true,deliverCallback,consumerTag -> {});
    }

}
